<template>
	<view>
		<view class="tab-page">
			<view class="list-wrapper" v-for="(item,index) in thList" :key="index">
				<view class="list-info">
					<view class="list-title">
						<view class="title-left">
							备件退还单号：{{item.refundNum}}<view class="copy" @click="copyOrderNum(item.refundNum)">复制</view>
						</view>
						<view class="title-right"
							:class="[item.dealStatus==0?'title-dyz':item.dealStatus==1?'title-finish':'']">
							{{item.dealStatus==0?'待处理':item.dealStatus==1?'已处理':''}}</view>
					</view>
				</view>
				<view class="list-main">
					<view class="item-main">
						<view class="main-left" style="width: 100%;">
							<view class="txt1">工单信息</view>
							<view class="txt2">维修工单-{{item.orderNum}}</view>
						</view>
					</view>
					<view class="item-main">
						<view class="main-left" v-if="item.dealStatus==0">
							<view class="txt1">申请退还数量</view>
							<view class="txt2">{{item.refundAmount}}</view>
						</view>
						<view class="main-left" v-if="item.dealStatus==1">
							<view class="txt1">实际退还数量</view>
							<view class="txt2">{{item.totalAmount}}</view>
						</view>
						<view class="main-left">
							<view class="txt1">退还申请人</view>
							<view class="txt2">{{item.refundUserName}}</view>
						</view>
					</view>
					<view class="item-main">
						<view class="main-left">
							<view class="txt1">退还审批人</view>
							<view class="txt2">{{item.dealUserName}}</view>
						</view>
						<view class="main-left">
							<view class="txt1">申请时间</view>
							<view class="txt2">{{item.createTime}}</view>
						</view>
					</view>
				</view>
				<view class="item-btn" v-if="item.dealStatus==0 && item.dealUser === userId">
					<view class="ruku" @click="selectDetail(item)">查看详情</view>
					<view class="su-line"></view>
					<view class="chuku" @click="togoApprovepage(item)">去审批</view>
				</view>
				<view class="item-btn" v-else @click="selectDetail(item)">
					<view class="ruku">查看详情</view>
				</view>
			</view>
			<u-loadmore v-if="total>5" :status="status" :line="true" />
		</view>
		<view class="empty-data" v-if="thList.length==0">
			<u-empty mode="data" :marginTop="100" text="暂无数据"></u-empty>
		</view>

		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userId: uni.getStorageSync('userInfo').userId, //当前登陆人id
				status: 'loadmore',
				activeStyle: {
					color: '#0F53AC',
					fontWeight: 'bold',
					transform: 'scale(1.05)'
				},
				inactiveStyle: {
					color: '#8c8c8c',
					transform: 'scale(1)'
				},
				itemStyle: {
					paddingLeft: '30rpx',
					paddingRight: '30rpx',
					height: '80rpx'
				},
				current: 0,
				list: [{
					name: '待维修工单',
				}, {
					name: '已维修工单',
				}],
				option: [
					{
						text: '全部',
						value: ''
					},
					{
						text: '待处理',
						value: 0
					},
					{
						text: '已处理',
						value: 1
					}
				],
				value1: '',
				params: {
					dealStatus: '0', //处理状态；0.待处理   1.已处理
					dealResult: '', //处理结果；1.全部退还   2.部分退还   3.未退还
					pn: 1,
					ps: 5,
					keyword: '',
					checkRoleFlag: 1
				},
				pages: 1,
				total: 0,
				thList: []
			}
		},
		onLoad() {
			this.getList();
		},
		onPullDownRefresh() {
			this.thList=[];
			this.params.pn=1;
			this.params.dealStatus=this.value1;
			this.getList();
			setTimeout(() => {
				uni.stopPullDownRefresh();
			}, 400)
		},
		
		methods: {
			leftClick(){
				uni.switchTab({
					url: '/pages/beijian/index'
				})
			},
			tabsClick(e) {
				this.current = e.index

			},
			toggleItem(val) {
				if (val === 1) {
					this.$refs.dropdown1.close()
				}
			},
			change1(val) {
				this.thList=[];
				this.params.pn=1;
				this.params.dealStatus=this.value1;
				this.getList();
			},
			//查看详情
			selectDetail(item) {
				uni.navigateTo({
					url: '/pages/subPackagesB/bjreturn/returnDetail?id='+item.id
				})
			},
			//去审批
			togoApprovepage(item){
				uni.navigateTo({
					url: '/pages/subPackagesB/bjreturn/returnVerify?id='+item.id
				})
			},
			togoReturnChange() {
				uni.navigateTo({
					url: '/pages/subPackagesB/bjreturn/returnApply'
				})
			},
			
			getList() {
				uni.$u.http.post(`/device/mobile/devicePartRefund/appPageList`, this.params).then(res => {
					if (res.code == 0) {
						this.thList = this.thList.concat(res.data.records);
						this.pages = res.data.pages;
						this.total = res.data.total;
					}
				}).catch(err => {})
			},
			copyOrderNum(data){
				uni.setClipboardData({
					data: data,
					success: function () {
						uni.$u.toast('复制成功')
					}
				});
			}
		},
		onReachBottom() {
			if (this.params.pn >= this.pages) return;
			this.status = 'loading';
			this.params.pn = ++this.params.pn;
			setTimeout(() => {
				this.getList()
				if (this.params.pn >= this.pages) this.status = 'nomore';
				else this.status = 'loading';
			}, 1000)
		}
	}
</script>

<style lang="scss">
	page {
		background: #ffffff;
	}

	.tab-page {
		margin-top: 2rpx;
	}

	.dropdown {
		.list2 {
			.sort {
				display: flex;
				justify-content: center;
				align-items: center;
				font-size: 26rpx;
				color: #000000;
				padding: 20rpx 0;
			}
		}

		.sort-list {
			width: 100%;
			height: 100vh;
			background: #9d9d9d;
			z-index: 22;
			position: absolute;

			.sort-item {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 10rpx 40rpx 10rpx 20rpx;
				font-size: 34rpx;
				border-bottom: 1px solid #f2f2f2;
				z-index: 99;
				position: relative;
				background: #fff;
			}

			.sort-item:last-child {
				border-bottom: none;
			}

			.sort-item:first-child {
				border-top: 1px solid #f2f2f2;
			}
		}
	}

	.list-wrapper {
		.list-info {
			margin-top: 10rpx;
			background: #fff;
			padding: 20rpx 40rpx;

			.list-title {
				display: flex;
				align-items: center;
				justify-content: space-between;

				.title-left {
					display: flex;
					align-items: center;
					font-size: 30rpx;
					color: #000000;

					.copy {
						color: #8c8c8c;
						font-size: 20rpx;
						margin-left: 10rpx;
						border-radius: 8rpx;
						background: #f2f2f2;
						padding: 5rpx 10rpx;
					}
				}

				.title-right {
					width: 96rpx;
					height: 48rpx;
					line-height: 48rpx;
					text-align: center;
					border-radius: 8rpx;
					font-size: 24rpx;
				}

				.title-ongoing {
					color: #0F53AC;
					background-color: rgba(2, 173, 130, 0.3);
				}

				.title-dyz {
					color: #1962e0;
					background-color: rgba(27, 114, 252, 0.3);
				}

				.title-close {
					color: #fc770a;
					background-color: rgba(255, 120, 10, 0.3);
				}

				.title-finish {
					color: #00bf56;
					background-color: rgba(0, 238, 107, 0.3);
				}
			}

		}

		.list-main {
			padding: 4rpx 10rpx 20rpx 10rpx;
			background: #fff;
			border-top: 1px solid #f2f2f2;
			border-bottom: 1px solid #f2f2f2;

			.item-main {
				display: flex;
				justify-content: space-between;
				padding: 4rpx 30rpx;

				.main-left {
					width: 50%;
					text-align: left;

					.txt1 {
						color: #8c8c8c;
						font-size: 28rpx;
						padding: 10rpx 0;
					}

					.txt2 {
						color: #2b2b2b;
						font-size: 28rpx;
					}
				}
			}

			.gz-desc {
				padding: 15rpx 30rpx;

				.title {
					font-size: 28rpx;
					color: #8c8c8c;
				}

				.desc-reason {
					font-size: 28rpx;
					color: #2b2b2b;
					margin-top: 15rpx;
					overflow: hidden;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;
				}
			}
		}

		.item-btn {
			display: flex;
			justify-content: space-around;
			align-items: center;
			padding: 20rpx 0;
			background: #fff;

			.chuku {
				width: 45%;
				font-size: 34rpx;
				color: #1962e0;
				text-align: center;
			}

			.ruku {
				width: 45%;
				font-size: 34rpx;
				color: #0F53AC;
				text-align: center;
			}

			.su-line {
				width: 4rpx;
				height: 50rpx;
				background: #f2f2f2;
			}
		}
	}

	.fixed-btn {
		position: fixed;
		bottom: 200rpx;
		right: 20rpx;
		z-index: 99;
		width: 160rpx;
		height: 160rpx;
		opacity: 1;
		background: rgba(2, 173, 130, 0.8);
		box-shadow: 6px 5px 20px 0px rgba(2, 173, 130, 0.4);
		border-radius: 50%;
		font-size: 28rpx;
		display: flex;
		align-items: center;
		flex-direction: column;
		color: #fff;

		.btn-icon {
			margin-top: 15rpx;

			image {
				width: 72rpx;
				height: 72rpx;
			}
		}
	}
</style>
